// 获取样式
function getStyle(obj, name) {
	if(obj.currentStyle) {
		if(name == "opacity") {
			return Math.round(parseFloat(obj.currentStyle[name]) * 100);
		} else {
			return parseInt(obj.currentStyle[name]);
		}
	} else {
		if(name == "opacity") {
			return Math.round(parseFloat(getComputedStyle(obj, false)[name]) * 100);
		} else {
			return parseInt(getComputedStyle(obj, false)[name]);
		}
	}
}

// 添加class
function addClass(obj, addClassName) {
	// 获取当前class名
	var objClassName = obj.className;
	
	if (objClassName == "") {
		// 把class添加给对象
		obj.className = addClassName;
	}else {
		// 把class名在空格的地方拆分成数组
		var arrClassName = objClassName.split(" ");
		
		// 把需要添加的class以空格拆分成数组
		var arraddClassName = addClassName.split(" ");
		
		// 把两个数组拼接
		var splicearr = arrClassName.concat(arraddClassName);
		
		// 把数组以空格分割成字符串
		var ClassName = splicearr.join(" ");
		
		// 把class添加给对象
		obj.className = ClassName;
	}
}
	
// 删除class
function removeClass(obj, removeClassName) {
	// 获取当前class名
	var objClassName = obj.className;
	
	// 把class名在空格的地方拆分成数组
	var arrClassName = objClassName.split(" ");
	
	// 把需要删除的class以空格拆分成数组
	var arrremoveClassName = removeClassName.split(" ");
	
	// 循环class数组
	for (var i = 0; i < arrClassName.length; i++){
		// 判断当前下标的class名是否和需要删除的相同
		for (var j = 0; j < arrremoveClassName.length; j++) {
			if (arrClassName[i] == arrremoveClassName[j]) {
				// 如果相同删除第当前下标的一个数组
				arrClassName.splice(i, 1);
			}
		}
	}
	
	// 把数组以空格分割成字符串
	var ClassName = arrClassName.join(" ");
	
	// 把class添加给对象
	obj.className = ClassName;
}

// 获取class
function getByClass(oParent, sClass) {
	var aEle = oParent.getElementsByTagName("*");
	var aResult = [];

	for(var i = 0; i < aEle.length; i++) {
		if(aEle[i].className == sClass) {
			aResult.push(aEle[i]);
		}
	}

	return aResult;
}

// 运动框架
function startMove(obj, json, fnEnd) {
	clearInterval(obj.timer);

	obj.timer = setInterval(function() {
		var bStop = true;

		for(var attr in json) {
			var cur = getStyle(obj, attr);
			var speed = (json[attr] - cur) / 6;
			speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);

			if(cur != json[attr]) {
				bStop = false;
			}

			if(attr == "opacity") {
				obj.style.filter = "alpha(opacity = " + (cur + speed) + ")";
				obj.style[attr] = (cur + speed) / 100;
			} else {
				obj.style[attr] = cur + speed + "px";
			}
		}

		if(bStop) {
			clearInterval(obj.timer);

			if(fnEnd) fnEnd();
		}
	}, 30);
}

// 获取鼠标坐标
function getPos(ev) {
	var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
	var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;

	return {
		x: ev.clientX + scrollLeft + "px",
		y: ev.clientY + scrollTop + "px"
	};
}

// 事件绑定
function myAddEvent(obj, ev, fn) {
	if(obj.attachEvent) {
		obj.attachEvent("on" + ev, fn);
	} else {
		obj.addEventListener(ev, fn, false);
	}
}